import { _mid } from "../math/index.js";
import { _mirror as mirrorPoint } from "../math/mirror.js";
import { _polygon } from "./polygon.js";
import { _colors } from "../color/index.js"

export const _mirror = (ctx, options, props) => {
    let { points = [],
        o, n,
        color,
        mirror
    } = options
    let { type, radio = 1 } = mirror
    let colors = _colors(color, n, 1)
    let _props = (index) => {
        let color = colors[index % n]
        return {
            stroke: color,
            ...props
        }
    }

    switch (type) {
        case 'edge':
            let midPoints = _mid(points)
            midPoints.forEach((t, i) => {
                let o2 = mirrorPoint(o, t, radio)
                _polygon(ctx, {
                    ...options,
                    mirror: null,
                    o: o2,
                }, _props(i))
            })
            break

        case 'vertex':
        default:
            points.forEach((t, i) => {
                let o2 = mirrorPoint(o, t, radio)
                _polygon(ctx, {
                    ...options,
                    mirror: null,
                    o: o2,
                }, _props(i))
            })
    }

}